package com.vdong.trade.trading.common.foundation;

import org.lamb.framework.common.exception.EventException;
import org.lamb.framework.common.util.BeanPlasticityUtill;
import org.lamb.framework.core.handler.LambHandler;
import org.lamb.framework.core.templete.LambResponseTemplete;
import reactor.core.publisher.Mono;

import static org.lamb.framework.common.enumeration.ExceptionEnum.ES00000002;

/**
 * @description: 基础接口层
 * @author: Mr.WangGang
 * @create: 2018-11-16 下午 6:17
 **/
public abstract class FoundationController extends LambHandler {
    public <T>Mono<LambResponseTemplete> returning(Class clazz,T data){
        if(data == null){
            try {
                return returning(clazz.newInstance());
            }catch (IllegalAccessException e) {
                throw new EventException(ES00000002);
            } catch (InstantiationException e) {
                throw new EventException(ES00000002);
            }
        };
        return returning(BeanPlasticityUtill.copy(clazz,data));
    }
}
